#ifndef ALGORITHM_H_
#define ALGORITHM_H_

/// Copy elements from one container to another if the elements fulfill a
/// predicate.  Standard C++ doesn't have copy_if().
template<class In, class Out, class Pred>
Out copy_if(In first, In last, Out res, Pred p)
{
    while( first != last ) {
        if( p(*first) ) *res++ = *first;
        ++first;
    }
    return res;
}

class Nothing {
public:
    Nothing() { }

    template<typename T>
    operator T*() const { return 0; } // support implicit-cast to type T*
    
    template<typename C, typename T>
    operator T C::*() const { return 0; } // implicit-cast to ptr-to-member C::*

private:
    void operator&() const; // do not allow taking address of.
};

const Nothing nil;

#endif
